package com.mcgrady.linear;

import org.junit.Test;

import java.util.Arrays;

/**
 * @author McGrady
 */
public class ArrayTest {
    @Test
    public void oneArrayBuild(){
        int[] arrA = {164,475,78};
        System.out.println(arrA[0]);
        System.out.println(arrA[1]);
        System.out.println(arrA[2]);

        int[] arrB = new int[3];
        arrB[0] = 6;
        arrB[1] = 78;
        arrB[2] = 343;
        System.out.println(arrB[0]);
        System.out.println(arrB[1]);
        System.out.println(arrB[2]);

        int[] arrC = {34,565,58} ;
        System.out.println(arrC);

        char[] arrD = {'h','o','w'};
        System.out.println(arrD);
        System.out.println("char数组内存地址："+arrD.toString());

        boolean[] arrE = new boolean[3];
        System.out.println(arrE[0]);
        System.out.println(arrE[1]);
        System.out.println(arrE[2]);
        System.out.println(arrE);
    }

    @Test
    public void oneArrayTraverse(){
        int[] arrA = {23,34,64};
        for(int i = 0,j = arrA.length; i < j;i++){
            System.out.println(arrA[i]);
        }

        for(int x : arrA){
            System.out.println(x);
        }

        System.out.println(Arrays.toString(arrA));
    }

    @Test
    public void twoArrayBuild(){
        int[][] arrA = {
                {34,56,67},
                {67,35,13},
                {63,12,68}
        };
        System.out.println(Arrays.deepToString(arrA));

        int[][] arrB = new int[3][4];
        arrB[0][0] = 35;
        arrB[0][1] = 68;
        arrB[0][2] = 34;
        arrB[0][3] = 12;
        arrB[1][0] = 43;
        arrB[1][0] = 56;
        arrB[1][1] = 98;
        arrB[1][2] = 42;
        arrB[1][3] = 48;
        arrB[2][0] = 57;
        arrB[2][1] = 46;
        arrB[2][2] = 95;
        arrB[2][3] = 47;
        System.out.println(Arrays.deepToString(arrB));
    }

    @Test
    public void twoArrayTraverse() {
        int[][] arrA = {
                {57,53,94},
                {23,56,21},
                {34,75,12}
        };
        for(int i = 0,j = arrA.length; i < j; i++){
            for(int m = 0,n = arrA[i].length; m < n; m++){
                System.out.println(arrA[i][m] + "\t");
            }
            System.out.println();
        }

        for(int[] e: arrA){
            for(int i : e){
                System.out.println(i + "\t");
            }
            System.out.println();
        }
    }
}
